﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Web.Caching;

/// <summary>
/// Summary description for DataProvider
/// </summary>
public class DataProvider
{
    public SqlConnection Connect()
    {
        SqlConnection conn = new SqlConnection();
        conn.ConnectionString = ConfigurationManager.ConnectionStrings["db_flowerConnectionString"].ConnectionString;
        if (conn.State.ToString() == "Open")
            conn.Close();
        conn.Open();
        return conn;
    }

    public DataTable sp_select(string strsql)
    {
        SqlConnection conn = Connect();
        DataTable dt = new DataTable();
        try
        {
            SqlDataAdapter da = new SqlDataAdapter(strsql, conn);
            da.Fill(dt);
            return dt;
        }
        catch { return dt; }
        finally { conn.Close(); }
    }
    public byte[] encryptData(string data)
    {
        System.Security.Cryptography.MD5CryptoServiceProvider md5Hasher = new System.Security.Cryptography.MD5CryptoServiceProvider();
        byte[] hashedBytes;
        System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
        hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(data));
        return hashedBytes;
    }
}